<?php
session_start();
require_once 'classes/Database.php';
require_once 'classes/ProductManager.php';
require_once 'classes/OrderManager.php';
require_once 'classes/CDKManager.php';

$productManager = new ProductManager();
$orderManager = new OrderManager();
$cdkManager = new CDKManager();

// 获取商品列表
$products = $productManager->getAllProducts();

// 获取统计数据
$productStats = $productManager->getProductStatistics();
$orderStats = $orderManager->getOrderStatistics();
$cdkStats = $cdkManager->getCDKStatistics();
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>CDK支付系统 - 演示页面</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        .hero-section {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 80px 0;
            text-align: center;
        }
        .feature-card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
            margin-bottom: 30px;
        }
        .feature-card:hover {
            transform: translateY(-5px);
        }
        .stat-card {
            background: white;
            border-radius: 10px;
            padding: 20px;
            text-align: center;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        .product-card {
            border: none;
            border-radius: 10px;
            box-shadow: 0 3px 10px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
        }
        .product-card:hover {
            box-shadow: 0 5px 20px rgba(0,0,0,0.15);
        }
        .nav-link {
            color: #6c757d;
            font-weight: 500;
        }
        .nav-link:hover, .nav-link.active {
            color: #007bff;
        }
        .footer {
            background: #343a40;
            color: white;
            padding: 40px 0;
            margin-top: 50px;
        }
    </style>
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-light bg-white shadow-sm">
        <div class="container">
            <a class="navbar-brand fw-bold text-primary" href="demo.php">
                <i class="fas fa-shopping-cart me-2"></i>CDK支付系统
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link active" href="#home">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#products">商品列表</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#features">系统功能</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="#stats">数据统计</a>
                    </li>
                </ul>
                <div class="d-flex">
                    <a href="admin/login.php" class="btn btn-outline-primary me-2">
                        <i class="fas fa-user-shield"></i> 后台管理
                    </a>
                    <a href="index.php" class="btn btn-primary">
                        <i class="fas fa-shopping-bag"></i> 开始购买
                    </a>
                </div>
            </div>
        </div>
    </nav>

    <!-- 英雄区域 -->
    <section id="home" class="hero-section">
        <div class="container">
            <h1 class="display-4 fw-bold mb-4">CDK支付系统</h1>
            <p class="lead mb-4">专业的虚拟商品销售与CDK码分发解决方案</p>
            <div class="row justify-content-center">
                <div class="col-md-8">
                    <div class="row">
                        <div class="col-md-4 mb-3">
                            <div class="stat-card">
                                <h3 class="text-primary"><?php echo $productStats['total_products']; ?></h3>
                                <p class="text-muted">上架商品</p>
                            </div>
                        </div>
                        <div class="col-md-4 mb-3">
                            <div class="stat-card">
                                <h3 class="text-success"><?php echo $orderStats['total_orders']; ?></h3>
                                <p class="text-muted">总订单数</p>
                            </div>
                        </div>
                        <div class="col-md-4 mb-3">
                            <div class="stat-card">
                                <h3 class="text-info"><?php echo $cdkStats['total_cdks']; ?></h3>
                                <p class="text-muted">可用CDK</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <a href="#products" class="btn btn-light btn-lg mt-4">
                <i class="fas fa-arrow-down"></i> 查看商品
            </a>
        </div>
    </section>

    <!-- 商品列表 -->
    <section id="products" class="py-5 bg-light">
        <div class="container">
            <div class="text-center mb-5">
                <h2 class="fw-bold">热门商品</h2>
                <p class="text-muted">选择您需要的虚拟商品</p>
            </div>
            <div class="row">
                <?php foreach ($products as $product): ?>
                <div class="col-md-4 mb-4">
                    <div class="card product-card h-100">
                        <div class="card-body">
                            <h5 class="card-title text-primary"><?php echo htmlspecialchars($product['name']); ?></h5>
                            <p class="card-text text-muted"><?php echo htmlspecialchars($product['description']); ?></p>
                            <div class="d-flex justify-content-between align-items-center mb-3">
                                <span class="h4 text-success mb-0">¥<?php echo number_format($product['price'], 2); ?></span>
                                <span class="badge bg-info">库存: <?php echo $product['stock']; ?></span>
                            </div>
                            <div class="d-grid">
                                <a href="buy.php?id=<?php echo $product['id']; ?>" class="btn btn-primary">
                                    <i class="fas fa-shopping-cart me-2"></i>立即购买
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                <?php endforeach; ?>
            </div>
        </div>
    </section>

    <!-- 系统功能 -->
    <section id="features" class="py-5">
        <div class="container">
            <div class="text-center mb-5">
                <h2 class="fw-bold">系统功能</h2>
                <p class="text-muted">完善的功能体系，满足您的业务需求</p>
            </div>
            <div class="row">
                <div class="col-md-4 mb-4">
                    <div class="card feature-card h-100">
                        <div class="card-body text-center">
                            <div class="mb-3">
                                <i class="fas fa-shopping-cart fa-3x text-primary"></i>
                            </div>
                            <h5 class="card-title">商品管理</h5>
                            <p class="card-text text-muted">支持商品上架、编辑、下架，实时库存管理</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 mb-4">
                    <div class="card feature-card h-100">
                        <div class="card-body text-center">
                            <div class="mb-3">
                                <i class="fas fa-key fa-3x text-success"></i>
                            </div>
                            <h5 class="card-title">CDK管理</h5>
                            <p class="card-text text-muted">批量导入CDK码，自动分配，使用状态跟踪</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 mb-4">
                    <div class="card feature-card h-100">
                        <div class="card-body text-center">
                            <div class="mb-3">
                                <i class="fas fa-credit-card fa-3x text-info"></i>
                            </div>
                            <h5 class="card-title">支付集成</h5>
                            <p class="card-text text-muted">集成易支付，支持多种支付方式，安全可靠</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 mb-4">
                    <div class="card feature-card h-100">
                        <div class="card-body text-center">
                            <div class="mb-3">
                                <i class="fas fa-chart-bar fa-3x text-warning"></i>
                            </div>
                            <h5 class="card-title">订单管理</h5>
                            <p class="card-text text-muted">完整的订单生命周期管理，支持退款操作</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 mb-4">
                    <div class="card feature-card h-100">
                        <div class="card-body text-center">
                            <div class="mb-3">
                                <i class="fas fa-shield-alt fa-3x text-danger"></i>
                            </div>
                            <h5 class="card-title">安全防护</h5>
                            <p class="card-text text-muted">多重安全验证，防止SQL注入，数据加密存储</p>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 mb-4">
                    <div class="card feature-card h-100">
                        <div class="card-body text-center">
                            <div class="mb-3">
                                <i class="fas fa-mobile-alt fa-3x text-secondary"></i>
                            </div>
                            <h5 class="card-title">响应式设计</h5>
                            <p class="card-text text-muted">完美适配PC、平板、手机等各类设备</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 数据统计 -->
    <section id="stats" class="py-5 bg-light">
        <div class="container">
            <div class="text-center mb-5">
                <h2 class="fw-bold">系统统计</h2>
                <p class="text-muted">实时数据监控，掌握业务动态</p>
            </div>
            <div class="row">
                <div class="col-md-3 mb-4">
                    <div class="stat-card">
                        <i class="fas fa-box fa-2x text-primary mb-3"></i>
                        <h3><?php echo $productStats['total_products']; ?></h3>
                        <p class="text-muted">商品总数</p>
                    </div>
                </div>
                <div class="col-md-3 mb-4">
                    <div class="stat-card">
                        <i class="fas fa-shopping-cart fa-2x text-success mb-3"></i>
                        <h3><?php echo $orderStats['total_orders']; ?></h3>
                        <p class="text-muted">总订单数</p>
                    </div>
                </div>
                <div class="col-md-3 mb-4">
                    <div class="stat-card">
                        <i class="fas fa-key fa-2x text-info mb-3"></i>
                        <h3><?php echo $cdkStats['total_cdks']; ?></h3>
                        <p class="text-muted">CDK总数</p>
                    </div>
                </div>
                <div class="col-md-3 mb-4">
                    <div class="stat-card">
                        <i class="fas fa-money-bill-wave fa-2x text-warning mb-3"></i>
                        <h3>¥<?php echo number_format($orderStats['total_amount'], 2); ?></h3>
                        <p class="text-muted">交易总额</p>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- 页脚 -->
    <footer class="footer">
        <div class="container">
            <div class="row">
                <div class="col-md-4 mb-4">
                    <h5><i class="fas fa-shopping-cart me-2"></i>CDK支付系统</h5>
                    <p class="text-muted">专业的虚拟商品销售与CDK码分发解决方案，为您的业务提供稳定可靠的技术支持。</p>
                </div>
                <div class="col-md-4 mb-4">
                    <h5>快速链接</h5>
                    <ul class="list-unstyled">
                        <li><a href="index.php" class="text-muted">购买页面</a></li>
                        <li><a href="admin/login.php" class="text-muted">后台管理</a></li>
                        <li><a href="check_orders.php" class="text-muted">订单查询</a></li>
                    </ul>
                </div>
                <div class="col-md-4 mb-4">
                    <h5>技术支持</h5>
                    <ul class="list-unstyled">
                        <li class="text-muted">邮箱: support@example.com</li>
                        <li class="text-muted">电话: 400-123-4567</li>
                        <li class="text-muted">工作时间: 9:00-18:00</li>
                    </ul>
                </div>
            </div>
            <hr class="my-4">
            <div class="text-center">
                <p class="text-muted mb-0">&copy; 2024 CDK支付系统. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 平滑滚动
        document.querySelectorAll('a[href^="#"]').forEach(anchor => {
            anchor.addEventListener('click', function (e) {
                e.preventDefault();
                const target = document.querySelector(this.getAttribute('href'));
                if (target) {
                    target.scrollIntoView({
                        behavior: 'smooth',
                        block: 'start'
                    });
                }
            });
        });

        // 导航栏激活状态
        const sections = document.querySelectorAll('section');
        const navLinks = document.querySelectorAll('.nav-link');

        window.addEventListener('scroll', () => {
            let current = '';
            sections.forEach(section => {
                const sectionTop = section.offsetTop;
                const sectionHeight = section.clientHeight;
                if (scrollY >= (sectionTop - 100)) {
                    current = section.getAttribute('id');
                }
            });

            navLinks.forEach(link => {
                link.classList.remove('active');
                if (link.getAttribute('href') === `#${current}`) {
                    link.classList.add('active');
                }
            });
        });
    </script>
</body>
</html>
